# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# 从环境变量中获取访问凭证。运行本代码示例之前，请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
auth = oss2.Auth('LTAI5tBWSfGYWw9cveErF9iU','eUPnw9SrEgFpbxyZDBKfYckToZuAQN')
# 填写Bucket所在地域对应的Endpoint。以华东1（杭州）为例，Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
# 填写存储空间名称，例如examplebucket。
bucket = oss2.Bucket(auth, 'https://oss-cn-beijing.aliyuncs.com', 'zddsc')
# 填写LiveChannel名称，例如test-channel。
channel_name = "test-channel"
channel_cfg = oss2.models.LiveChannelInfo(target = oss2.models.LiveChannelInfoTarget())
channel = bucket.create_live_channel(channel_name, channel_cfg)
publish_url = channel.publish_url
# 生成RTMP推流的签名URL，并设置过期时间为3600秒。
signed_publish_url = bucket.sign_rtmp_url(channel_name, "playlist.m3u8", 3600)
# 打印未签名推流地址。
print('publish_url='+publish_url)
# 打印签名推流地址。
print('signed_publish_url='+signed_publish_url)